#include<iostream>
#include <string>
#include <string.h>
#include <queue>
using namespace std;
typedef struct node{
    int data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
typedef struct node *BTree;
BTree CreateBTree(char a[],int i);
int wpl_levelorder(BTree root);
int main()
{
	int i,f=0;
	char c[1000];
	BTree b;
	gets(c);
	for(i=0;c[i];i++)
	{
		if(c[i]!='#')
		{
			f=1;
			break;
		}
	}
	if(!f)
	cout<<"0";
	else
	{
		b= CreateBTree( c,1);
	cout<<wpl_levelorder(b);
	}
	
	
}
BTree CreateBTree(char a[],int i)
{
	BTree b;
	if(i>=strlen(a))return NULL;
	if(a[i]=='#')return NULL;
	b=new BTNode;
	b->data=a[i]-'0';
	b->lchild=CreateBTree(a,2*i);
	b->rchild=CreateBTree(a,2*i+1);
	return b;
}
int wpl_levelorder(BTree root)
{
	BTree q[100];
	int end1,end2;
	end1=end2=0;
	int wpl=0,deep=0;
	BTree lastnode,newnode;
	lastnode=root;
	newnode=NULL;
	q[end2++]=root;
	while(end1!=end2)
	{
		BTree t=q[end1++];
		if(t->lchild==NULL&&t->rchild==NULL)
		wpl+=(t->data)*deep;
		if(t->lchild!=NULL)
		{
			q[end2++]=t->lchild;
			newnode=t->lchild;
		}
		if(t->rchild!=NULL)
		{
			q[end2++]=t->rchild;
			newnode=t->rchild;
		}
		if(t==lastnode)
		{
			lastnode=newnode;
			deep++;
		}
	}
	return wpl;
}
